<template>
	<view class="sub-appeal-content">
		<view class="home-top">
			<view class="home-title">超级返</view>
			<image src="../../../static/common/sub-back-icon.png" class="sub-back-icon" @tap="backpage"></image>
			<image src="../../../static/common/sbu-home-top-icon.png" class="sub-home-top-icon" @tap="contactKF"></image>
		</view>
		
		<view class="nav-tab">
			<view class="buying" :class="{'select':navIndex==1}" @tap="changeNav(1)">收到的申诉</view>
			<view class="buying" :class="{'select':navIndex==2}" @tap="changeNav(2)">提出的申诉</view>
		</view>
		
		<view class="goods-box">
			<scroll-view class="list" scroll-y="true" @scrolltolower="loadMore">
				<view class="list-box" v-if="init==1">
					<view class="nodatalist" v-if="AcceptList.length ==0">
						<image src="../../../static/common/nodata-sub.png" class="nodata"></image>
					</view>
					<senAppeal v-else v-for="(item,index) in AcceptList" :key="index"
						@goAppealDetail="goAppealDetail"
						:appealDetail="item"></senAppeal>
				</view>
				<view class="list-box"  v-if="init==2">
					<view class="nodatalist" v-if="SendList.length ==0">
						<image src="../../../static/common/nodata-sub.png" class="nodata"></image>
					</view>
					<senAppeal v-else  v-for="(item,index) in SendList" :key="index"
						@goAppealDetail="goAppealDetail"
						:appealDetail="item"></senAppeal>
				</view>
				
			</scroll-view>
		</view>
		
	</view>
</template>

<script>
	const util = require('../../../util/util.js');
	import senAppeal from'../../../components/sub-appeal/sub-appeal.vue'
	export default{
		name:"subAppeal",
		data(){
			return{
				AcceptList:[],
				SendList:[],
				init:1,//页面初始化显示收到的申诉
				navIndex:1,
				apptoken:"",
				pageIndex:1,
				nodata1:false,
				nodata2:false
			}
		},
		components:{
			senAppeal
		},
		onLoad() {
			this.apptoken = uni.getStorageSync("apptoken");
			//初始化加载收到的申诉
			this.getAcceptlist();
		},
		methods:{
			goAppealDetail(id){
				//申诉详情
				uni.navigateTo({
					url:'../sub-appealDetail/sub-appealDetail?appealId='+id,
				})
			},
			changeNav(n){
				this.navIndex = n;
				this.init = n;
				this.pageIndex = 1;
				this.nodata1 = false;
				this.nodata2 = false;
				this.AcceptList = [];
				this.SendList = [];
				if(n==1){
					this.getAcceptlist();
				}else{
					this.getSendlist();
				}
			},
			getAcceptlist(type){
				//收到的申诉
				let _this = this;
				uni.request({
					url:this.$API.URL + this.$API.appeal_list1,
					data:{apptoken:this.apptoken,pageIndex:this.pageIndex},
					success(res) {
						console.log(res)
						if(res.data.success){
							let d = res.data.data;
							if(type){
								//分页
								
								if(d?.length<1 && _this.pageIndex !=1){
									_this.$CommonJS.showToast("没有更多数据了");
									_this.nodata1 = true;
									return;
								}else{
									d.forEach(item=>{
										_this.AcceptList.push(item)
									})
								}
								
							}else{
								_this.AcceptList = [];
								_this.nodata1 = false;
								_this.AcceptList = d;
							}
							_this.pageIndex ++;
							console.log(_this.AcceptList)
							console.log(_this.AcceptList.length)
						}else{
							_this.$CommonJS.showToast(res.data.msg)
						}
					}
				})
			},
			getSendlist(type){
				//提出的申诉
				let _this = this;
				uni.request({
					url:this.$API.URL + this.$API.appeal_list2,
					data:{apptoken:this.apptoken,pageIndex:this.pageIndex},
					success(res) {
						console.log(res)
						if(res.data.success){
							let d = res.data.data;
							if(type){
								//分页
								
								if(d?.length<1 && _this.pageIndex !=1){
									_this.$CommonJS.showToast("没有更多数据了");
									_this.nodata2 = true;
									return;
								}else{
									d.forEach(item=>{
										_this.SendList.push(item)
									})
								}
								
							}else{
								_this.SendList = [];
								_this.nodata2 = false;
								_this.SendList = d;
							}
							_this.pageIndex ++;
							
						}else{
							_this.$CommonJS.showToast(res.data.msg)
						}
					}
				})
			},
			//防抖事件//分页
			loadMore: util.throttle(function(e) {
				console.log("加载第"+this.pageIndex+"页数据")
				// if(!this.nodata){
					
					
				// }
				if(this.init == 2 && !this.nodata1){
					this.getSendlist("loadMore")
				}else if(this.init == 1 && !this.nodata2){
					this.getAcceptlist("loadMore")
				}
				
			}, 300),
			backpage(){
				this.$CommonJS.navigateBack();
			},
			contactKF(){
				this.$CommonJS.navigateTo('../../subBack/sub-kefu/sub-kefu')
			}
		}
	}
</script>

<style scoped>
	@import url("sub-appeal.css");
</style>
